package org.example.src.repository;

import org.example.src.entity.Company;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface CompanyRepository extends JpaRepository<Company, Long> {
    Optional<Company> findByCompanyName(String companyName);

    @Query("SELECT c FROM Company c WHERE c.industry = :industry")
    List<Company> findByIndustry(@Param("industry") String industry);

    @Query("SELECT c FROM Company c WHERE c.isApproved = :isApproved")
    List<Company> findByApprovalStatus(@Param("isApproved") Boolean isApproved);

    @Query("SELECT c FROM Company c WHERE c.businessLicense = :businessLicense")
    Optional<Company> findByBusinessLicense(@Param("businessLicense") String businessLicense);

    @Query("SELECT c FROM Company c WHERE c.companyName LIKE %:name%")
    List<Company> findByNameContaining(@Param("name") String name);

    @Query("SELECT COUNT(c) FROM Company c WHERE c.isApproved = true")
    Long countApprovedCompanies();
}